<?php
/**
 * Base class for all synchronizers 
 * @author Artur Kmera <artur.kmera@3code.pl>
 * @version 0.9
 * @package ORM
 * @subpackage Schema
 * @link http://arrowplatform.org/orm
 * @copyright 2011 Arrowplatform 
 * @license GNU LGPL
*/
abstract class AbstractSynchronizer{
	
	/**
	 * Strict mode for synchronization
	 * ( schema 100% equals witch datasource )
	 * @var int
	 */
	const MODE_STRICT = 0;
	/**
	 * Loose mode for synchronization
	 * ( datasource can carry more data than schema )
	 * @var int
	 * @todo implement
	 * @todo write tests
	 */
	const MODE_LOOSE = 1;
	
	/**
	 * This mode synchronizing only tables that existing in schema
	 * Best way to use multiple schema files for difrent modules
	 * @var int
	 * @todo implement
	 * @todo write tests
	 */
	const MODE_ONLY_SCHEMA_TABLES = 2;
	
	/**
	 * Current synchronization mode ( strict or loose )
	 * @var int
	 */
	private $mode = self::MODE_STRICT;
	
	/**
	 * Sets synchronization mode
	 * @param int $mode
	 */
	public function setMode($mode){
		$this->mode = $mode;
	}

	/**
	 * Get synchronization mode
	 * @return int
	 */
	public function getMode(){
		return $this->mode;
	}

	/**
	 * Resolve single mismatch
	 * @param Datasource $ds
	 * @param AbstractMismatch $mismatch
	 * @return ResolvetMismatch
	 */
	abstract public function resolveMismatch( AbstractMismatch $mismatch);
	
	/**
	 * Return all mismatches ( SchemaMismatch and DatasourceMismatch )
	 * <code>
	 * <?php
	 * $mismatches = $synchro->getSchemaMismatches($db, $schema);
	 * foreach($mismatches as $mismatch){
	 *      print $mismatch->toString()."\n";
	 * }
	 * @param Datasource $ds
	 * @param Schema $schema
	 * @return AbstractMismatch []
	 */
	abstract public function getSchemaMismatches( Datasource $ds, Schema $schema);
	
	/**
	 * Synchronize datasource with schema using mode flag
	 * <code>
	 * $schemaReader = new SchemaReader();
	 * $schema = $schemaReader->readSchemaFromFile($testFile);
	 * $reader = new ConfigReader();
	 * $result = $reader->readConfigFromFile($dbConfFile);
	 * $db = new Database( $result[0]->datasources[0] );
	 * $db->connect();
	 * 
	 * 
	 * $synchro = new AbstractSynchronizer(); //eg MysqlSynchronizer
	 * </code>
	 * @param Datasource $ds
	 * @param Schema $schema
	 * @return ResolvetMismatch []
	 */
	abstract public function schemaToDatasource( Datasource $ds, Schema $schema);
	
	/**
	 * Putting all  DatasourceMismatch es to schema 
	 * @param Datasource $ds
	 * @param Schema $schema
	 * @return ResolvetMismatch []
	 */
	abstract public function datasourceToSchema( Datasource $ds, Schema $schema);
	
}

?>